package com.hs.server.service.impl;

import com.hs.server.config.MyConfig;
import com.hs.server.domain.VehZnshinfo;
import com.hs.server.dto.Vehicle;
import com.hs.server.mapper.XbjcMapper;
import com.hs.server.service.VehQueuexxbService;
import com.hs.server.service.VehZnshinfoService;
import com.hs.server.service.VehZnshzlzpxxService;
import com.hs.server.service.WebApiService;
import com.hs.server.thirdPart.IOpenService;
import com.hs.server.thirdPart.hs.params.IQ_18C22;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Description
 * @Author: chenjiarui
 * @Date: 2021-07-12 15:26
 */
@Service
@Slf4j
public class WebApiServiceImpl implements WebApiService {
    @Autowired
    private IOpenService openService;
    @Autowired
    private MyConfig myConfig;
    @Autowired
    private XbjcMapper xbjcMapper;
    @Autowired
    private VehZnshzlzpxxService vehZnshzlzpxxService;
    @Autowired
    private VehZnshinfoService vehZnshinfoService;
    @Autowired
    private VehQueuexxbService vehQueuexxbService;
    private static final String LINKED_ZPZL_LIST = "0111,0112,0348,0322,0321,0352,0342,0344";
    // 定义常量
    private static final int RESULT_SUCCESS = 1; // 审核通过
    private static final int RESULT_MANUAL_REVIEW = 4; // 建议人工
    private static final int RESULT_FAILED = 5; // 审核不通过

    private static final String SHZT_PASSED = "1";
    private static final String SHZT_FAILED = "5";
    private static final String SHZT_MANUAL = "4";

    /**
     * 读取新版检测系统照片信息并入库
     */
    @Override
    public void GetXbjcxtZp() {
        //设定查询条件
        IQ_18C22 iq_18C22 = new IQ_18C22();
        //设定查询数据数量
        iq_18C22.setFhzdjls("10");
        //设定开始查询的日期（pssj）
        iq_18C22.setQsrq(myConfig.startTime);//LocalDate.now().toString()
        //开始查询(获取待比对的检验记录)
        List<Vehicle> list = openService.IQ_18C22_1(iq_18C22,"2");
        log.info("【获取到" + list.size() + "条车辆预审核数据】");
        if (list!=null){
            //查询流水号下的所有审核信息并入库
            for (Vehicle v : list) {
                iq_18C22.setLsh(v.getJylsh());
                iq_18C22.setVehicle(v);
                openService.IQ_18C22_2(iq_18C22);
                try {
                    Thread.sleep((long) (myConfig.timeInterval * 0.2));//1s
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    @Override
    public void judgeFinish(){
        List<String> needJudgeJylshList = xbjcMapper.judgeFinish(myConfig.getStartTime());
        log.info("共{}条整车数据待判断",needJudgeJylshList.size());
        for (String jylsh : needJudgeJylshList){
            int unreviewedCount = xbjcMapper.getUnreviewedCount(jylsh);
            if (unreviewedCount==0) {
                log.info("processReviewResult: 流水号[{}]所有照片已审核完成，开始判定整车审核结果。", jylsh);
                finalizeVehicleReview(jylsh);
            }
        }
    }

    @Override
    public void judgeTaskFinish() {
        String needJudgeTaskLsh = vehQueuexxbService.judgeTaskFinish();
        if (StringUtils.isNotBlank(needJudgeTaskLsh)){
            log.info("judgeTaskFinish: 流水号[{}]作业数据已删除。", needJudgeTaskLsh);
            vehQueuexxbService.delWork(needJudgeTaskLsh,null);
        }
    }

    /**
     * 处理车辆最终审核结果
     * @param lsh
     * @param vehZnshinfo
     * @return
     */
    private void finalizeVehicleReview(String lsh) {
        VehZnshinfo vehZnshinfo = vehZnshinfoService.GetVehZnshinfoByLsh(lsh);
        if (vehZnshinfo == null) {//可能数据表清空了，没数据，不处理
            xbjcMapper.updateVehFlowYshbj(lsh, "3");
            return;
        }
        // 模拟等待，实际应移除或替换为异步处理
        try {
            Thread.sleep(1500L);
        } catch (InterruptedException e) {
            log.error("finalizeVehicleReview: 线程休眠被中断", e);
            Thread.currentThread().interrupt();
        }

        // 获取所有照片的审核状态
        List<String> shztList = new ArrayList<>(vehZnshzlzpxxService.getShztsByLsh(lsh));
        log.info("finalizeVehicleReview: 流水号【{}】最终所有照片修订后审核结果：{}", lsh, shztList);

        // 获取不通过的zpzl
        List<String> btgZpzlList = new ArrayList<>(vehZnshzlzpxxService.getBtgZpzls(lsh));

        vehZnshinfo.setShbtgx(btgZpzlList.isEmpty() ? "" : String.join(",", btgZpzlList));
        vehZnshinfo.setCzzt("1"); // 设置为已检验

        int finalShzt = determineFinalReviewStatus(shztList);
        vehZnshinfo.setShzt(String.valueOf(finalShzt));
        vehZnshinfoService.updateVehZnshinfo(vehZnshinfo);
        xbjcMapper.updateVehFlowYshbj(vehZnshinfo.getLsh(), mapFinalStatusToFlowStatus(finalShzt));
        log.info("finalizeVehicleReview: 流水号[{}]整车审核结果更新为:{}", lsh, finalShzt);
    }

    /**
     * 确定新版流水表预审核标记状态
     * @param finalShzt
     * @return
     */
    private String mapFinalStatusToFlowStatus(int finalShzt) {
        switch (finalShzt) {
            case RESULT_SUCCESS:
                return "1";
            case RESULT_FAILED:
                return "2";
            case RESULT_MANUAL_REVIEW:
                return "7";
            default:
                return "8"; // 未知状态
        }
    }

    /**
     * 确定最终审核状态
     * @param shztList
     * @return
     */
    private int determineFinalReviewStatus(List<String> shztList) {
        if (shztList.contains(SHZT_FAILED)) {
            return RESULT_FAILED;
        }
        if (shztList.contains(SHZT_MANUAL)) {
            return RESULT_MANUAL_REVIEW;
        }
        // 确保所有照片都通过或无需审核
        if (shztList.stream()
                .filter(Objects::nonNull)  // 先过滤掉null
                .allMatch(s -> s.equals(SHZT_PASSED) || s.equals("3"))) {
            return RESULT_SUCCESS;
        }
        return RESULT_MANUAL_REVIEW; // 默认建议人工，或者根据实际业务逻辑调整
    }

    /**
     * 处理关联照片的审核结果
     * @param lsh
     * @return
     */
//    private Map<String, String> processLinkedPhotos(String lsh) {
//        Map<String, String> linkedMap = new HashedMap();
//        linkedMap.putAll(handleTripodLink(lsh,"0111","0112","[三脚架目标检测-是否存在]","jy_001_002","jy_002_002"));
//        linkedMap.putAll(handleTripodLink(lsh,"0321","0352","[车灯-是否亮]","jy_031_001","jy_041_001"));
//        linkedMap.putAll(handleTripodLink(lsh,"A110","A111","[车牌识别-与实际值比对]","jy_080_001","jy_081_001"));
//        linkedMap.putAll(handleTripodLink(lsh,"0111","0112","[车身颜色-与实际值比对]","jy_001_003","jy_002_003"));
//        return linkedMap;
//    }

    /**
     * 0111-0112-关联三角架
     * @param lsh
     * @return 0111-0112的shzt列表
     */
//    private Map<String,String> tripodHandle(String lsh){
//        log.info("进入【0111-0112关联三角架】");
//        Map<String,String> shztMap = new HashedMap();
//        //0111-0112 任意一张有放三角架就通过
//        VehZnshzlzpxx vehZnshzlzpxx_0111 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0111");
//        VehZnshzlzpxx vehZnshzlzpxx_0112 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0112");
//        String tripod = "[三角架-是否存在]";
//        String shzt_0111 = vehZnshzlzpxx_0111==null?"":vehZnshzlzpxx_0111.getShzt();
//        String shzt_0112 = vehZnshzlzpxx_0112==null?"":vehZnshzlzpxx_0112.getShzt();
//
//        if (vehZnshzlzpxx_0111!=null && vehZnshzlzpxx_0112!=null){//有这两种照片,并且都开启了三角架配置，就需要关联三角架
//            //null.contains会报空指针异常，需先转换
//            String shbtgyy_0111 = vehZnshzlzpxx_0111.getShbtgyy()==null?"":vehZnshzlzpxx_0111.getShbtgyy();
//            String shbtgyy_0112 = vehZnshzlzpxx_0112.getShbtgyy()==null?"":vehZnshzlzpxx_0112.getShbtgyy();
//
//            List<String> shbtgyy_0111_list = StringUtils.isNotBlank(shbtgyy_0111)? Arrays.asList(shbtgyy_0111.split(",")):new ArrayList<>();
//            List<String> shbtgyy_0112_list = StringUtils.isNotBlank(shbtgyy_0112)?Arrays.asList(shbtgyy_0112.split(",")):new ArrayList<>();
//
//            String jyx_0111 = vehZnshzlzpxx_0111.getJyx()==null?"":vehZnshzlzpxx_0111.getJyx();
//            String jyx_0112 = vehZnshzlzpxx_0112.getJyx()==null?"":vehZnshzlzpxx_0112.getJyx();
//
//            if (jyx_0111.contains("jy_001_002") && jyx_0112.contains("jy_002_002")){//是否都开启了三脚架检验配置
//                //重新修正版本 2022-05-13
//                if ((shbtgyy_0111.contains(tripod) && !shbtgyy_0112.contains(tripod))){
//                    //shbtgyy_0111去除[三角架-是否存在]
//                    shbtgyy_0111_list = shbtgyy_0111_list.stream().filter( v-> !tripod.equals(v)).collect(Collectors.toList());
//                }
//                if (!shbtgyy_0111.contains(tripod) && shbtgyy_0112.contains(tripod)){
//                    //shbtgyy_0112去除[三角架-是否存在]
//                    shbtgyy_0112_list = shbtgyy_0112_list.stream().filter( v-> !tripod.equals(v)).collect(Collectors.toList());
//                }
//                shzt_0111 = shbtgyy_0111_list.size()==0?"1":"5";
//                shzt_0112 = shbtgyy_0112_list.size()==0?"1":"5";
//                //todo 修改关联照片的shzt为处理后的结果以及去除审核不通过原因的关联检验项
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0111,String.join(",",shbtgyy_0111_list),"0111");
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0112,String.join(",",shbtgyy_0112_list),"0112");
//            }
//        }
//        if (StringUtils.isNotBlank(shzt_0111))
//            shztMap.put("0111",shzt_0111);//加入已经处理过的0111判断结果
//        if (StringUtils.isNotBlank(shzt_0112))
//            shztMap.put("0112",shzt_0112);//加入已经处理过的0112判断结果
//        log.info("出来【0111-0112关联三角架】");
//        return shztMap;
//    }
//
//    /**
//     * 0348-0322-关联尾灯
//     * @param lsh
//     * @return 0348-0322的shzt列表
//     */
//    private Map<String,String> taillightHandle(String lsh){
//        log.info("进入【0348-0322关联尾灯】");
//        Map<String,String> shztMap = new HashedMap();
//        //0348-0322 任意一张尾灯亮就通过
//        VehZnshzlzpxx vehZnshzlzpxx_0348 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0348");
//        VehZnshzlzpxx vehZnshzlzpxx_0322 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0322");
//        String taillight = "[尾灯-是否亮起]";
//        String shzt_0348 = vehZnshzlzpxx_0348==null?"":vehZnshzlzpxx_0348.getShzt();
//        String shzt_0322 = vehZnshzlzpxx_0322==null?"":vehZnshzlzpxx_0322.getShzt();
//
//        if (vehZnshzlzpxx_0348!=null && vehZnshzlzpxx_0322!=null){//有这两种照片,并且都开启了尾灯配置，就需要关联尾灯
//            //null.contains会报空指针异常，需先转换
//            String shbtgyy_0348 = vehZnshzlzpxx_0348.getShbtgyy()==null?"":vehZnshzlzpxx_0348.getShbtgyy();
//            String shbtgyy_0322 = vehZnshzlzpxx_0322.getShbtgyy()==null?"":vehZnshzlzpxx_0322.getShbtgyy();
//
//            List<String> shbtgyy_0348_list = StringUtils.isNotBlank(shbtgyy_0348)?Arrays.asList(shbtgyy_0348.split(",")):new ArrayList<>();
//            List<String> shbtgyy_0322_list = StringUtils.isNotBlank(shbtgyy_0322)?Arrays.asList(shbtgyy_0322.split(",")):new ArrayList<>();
//
//            String jyx_0348 = vehZnshzlzpxx_0348.getJyx()==null?"":vehZnshzlzpxx_0348.getJyx();
//            String jyx_0322 = vehZnshzlzpxx_0322.getJyx()==null?"":vehZnshzlzpxx_0322.getJyx();
//
//            if (jyx_0348.contains("jy_015_003") && jyx_0322.contains("jy_014_003")){//是否都开启了尾灯检验配置
//                //重新修正版本 2022-05-13
//                if ((shbtgyy_0348.contains(taillight) && !shbtgyy_0322.contains(taillight))){
//                    shbtgyy_0348_list = shbtgyy_0348_list.stream().filter( v-> !taillight.equals(v)).collect(Collectors.toList());
//                }
//                if (!shbtgyy_0348.contains(taillight) && shbtgyy_0322.contains(taillight)){
//                    shbtgyy_0322_list = shbtgyy_0322_list.stream().filter( v-> !taillight.equals(v)).collect(Collectors.toList());
//                }
//                shzt_0348 = shbtgyy_0348_list.size()==0?"1":"5";
//                shzt_0322 = shbtgyy_0322_list.size()==0?"1":"5";
//
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0348,String.join(",",shbtgyy_0348_list),"0348");
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0322,String.join(",",shbtgyy_0322_list),"0322");
//            }
//        }
//        if (StringUtils.isNotBlank(shzt_0348))
//            shztMap.put("0348",shzt_0348);//加入已经处理过的0348判断结果
//        if (StringUtils.isNotBlank(shzt_0322))
//            shztMap.put("0322",shzt_0322);//加入已经处理过的0322判断结果
//        log.info("出来【0348-0322关联尾灯】");
//        return shztMap;
//    }
//
//    /**
//     * 0321-0352-关联车牌号
//     * @param lsh
//     * @return 0321-0352的shzt列表
//     */
//    private Map<String,String> plateHandle(String lsh){
//        log.info("进入【0321-0352关联车牌号】");
//        Map<String,String> shztMap = new HashedMap();
//        //0321-0352 任意一张识别到车牌号就通过
//        VehZnshzlzpxx vehZnshzlzpxx_0321 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0321");
//        VehZnshzlzpxx vehZnshzlzpxx_0352 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0352");
//        String plate = "[车牌号-与实际值比对]";
//        String shzt_0321 = vehZnshzlzpxx_0321==null?"":vehZnshzlzpxx_0321.getShzt();
//        String shzt_0352 = vehZnshzlzpxx_0352==null?"":vehZnshzlzpxx_0352.getShzt();
//
//        if (vehZnshzlzpxx_0321!=null && vehZnshzlzpxx_0352!=null){//有这两种照片,并且都开启了车牌号配置，就需要关联车牌号
//            //null.contains会报空指针异常，需先转换
//            String shbtgyy_0321 = vehZnshzlzpxx_0321.getShbtgyy()==null?"":vehZnshzlzpxx_0321.getShbtgyy();
//            String shbtgyy_0352 = vehZnshzlzpxx_0352.getShbtgyy()==null?"":vehZnshzlzpxx_0352.getShbtgyy();
//
//            List<String> shbtgyy_0321_list = StringUtils.isNotBlank(shbtgyy_0321)?Arrays.asList(shbtgyy_0321.split(",")):new ArrayList<>();
//            List<String> shbtgyy_0352_list = StringUtils.isNotBlank(shbtgyy_0352)?Arrays.asList(shbtgyy_0352.split(",")):new ArrayList<>();
//
//            String jyx_0321 = vehZnshzlzpxx_0321.getJyx()==null?"":vehZnshzlzpxx_0321.getJyx();
//            String jyx_0352 = vehZnshzlzpxx_0352.getJyx()==null?"":vehZnshzlzpxx_0352.getJyx();
//
//            if (jyx_0321.contains("jy_011_002") && jyx_0352.contains("jy_012_002")){//是否都开启了尾灯检验配置
//                //重新修正版本 2022-05-13
//                if ((shbtgyy_0321.contains(plate) && !shbtgyy_0352.contains(plate))){
//                    shbtgyy_0321_list = shbtgyy_0321_list.stream().filter( v-> !plate.equals(v)).collect(Collectors.toList());
//                }
//                if (!shbtgyy_0321.contains(plate) && shbtgyy_0352.contains(plate)){
//                    shbtgyy_0352_list = shbtgyy_0352_list.stream().filter( v-> !plate.equals(v)).collect(Collectors.toList());
//                }
//                shzt_0321 = shbtgyy_0321_list.size()==0?"1":"5";
//                shzt_0352 = shbtgyy_0352_list.size()==0?"1":"5";
//
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0321,String.join(",",shbtgyy_0321_list),"0321");
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0352,String.join(",",shbtgyy_0352_list),"0352");
//            }
//        }
//        if (StringUtils.isNotBlank(shzt_0321))
//            shztMap.put("0321",shzt_0321);//加入已经处理过的0321判断结果
//        if (StringUtils.isNotBlank(shzt_0352))
//            shztMap.put("0352",shzt_0352);//加入已经处理过的0352判断结果
//        log.info("出来【0321-0352关联车牌号】");
//        return shztMap;
//    }
//
//    /**
//     * 0321-0352-关联大灯
//     * @param lsh
//     * @return
//     */
//    private Map<String,String> headlightsHandle(String lsh){
//        log.info("进入【0321-0352关联大灯】");
//        Map<String,String> shztMap = new HashedMap();
//        //0321-0352 任意一张识别到车牌号就通过
//        VehZnshzlzpxx vehZnshzlzpxx_0321 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0321");
//        VehZnshzlzpxx vehZnshzlzpxx_0352 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0352");
//        String headlights = "[左右大灯-是否亮起（两个灯至少要亮一个）]";
//        String shzt_0321 = vehZnshzlzpxx_0321==null?"":vehZnshzlzpxx_0321.getShzt();
//        String shzt_0352 = vehZnshzlzpxx_0352==null?"":vehZnshzlzpxx_0352.getShzt();
//
//        if (vehZnshzlzpxx_0321!=null && vehZnshzlzpxx_0352!=null){//有这两种照片,并且都开启了大灯配置，就需要关联大灯
//            //null.contains会报空指针异常，需先转换
//            String shbtgyy_0321 = vehZnshzlzpxx_0321.getShbtgyy()==null?"":vehZnshzlzpxx_0321.getShbtgyy();
//            String shbtgyy_0352 = vehZnshzlzpxx_0352.getShbtgyy()==null?"":vehZnshzlzpxx_0352.getShbtgyy();
//
//            List<String> shbtgyy_0321_list = StringUtils.isNotBlank(shbtgyy_0321)?Arrays.asList(shbtgyy_0321.split(",")):new ArrayList<>();
//            List<String> shbtgyy_0352_list = StringUtils.isNotBlank(shbtgyy_0352)?Arrays.asList(shbtgyy_0352.split(",")):new ArrayList<>();
//
//            String jyx_0321 = vehZnshzlzpxx_0321.getJyx()==null?"":vehZnshzlzpxx_0321.getJyx();
//            String jyx_0352 = vehZnshzlzpxx_0352.getJyx()==null?"":vehZnshzlzpxx_0352.getJyx();
//
//            if (jyx_0321.contains("jy_011_001") && jyx_0352.contains("jy_012_001")){//是否都开启了大灯检验配置
//                if ((shbtgyy_0321.contains(headlights) && !shbtgyy_0352.contains(headlights))){
//                    shbtgyy_0321_list = shbtgyy_0321_list.stream().filter( v-> !headlights.equals(v)).collect(Collectors.toList());
//                }
//                if (!shbtgyy_0321.contains(headlights) && shbtgyy_0352.contains(headlights)){
//                    shbtgyy_0352_list = shbtgyy_0352_list.stream().filter( v-> !headlights.equals(v)).collect(Collectors.toList());
//                }
//                shzt_0321 = shbtgyy_0321_list.size()==0?"1":"5";
//                shzt_0352 = shbtgyy_0352_list.size()==0?"1":"5";
//
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0321,String.join(",",shbtgyy_0321_list),"0321");
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0352,String.join(",",shbtgyy_0352_list),"0352");
//            }
//        }
//        if (StringUtils.isNotBlank(shzt_0321))
//            shztMap.put("0321",shzt_0321);//加入已经处理过的0321判断结果
//        if (StringUtils.isNotBlank(shzt_0352))
//            shztMap.put("0352",shzt_0352);//加入已经处理过的0352判断结果
//        log.info("出来【0321-0352关联大灯】");
//        return shztMap;
//    }
//
//
//    /**
//     * 0342-0344-关联动态开始和结束车牌号
//     * @param lsh
//     * @return
//     */
//    private Map<String,String> dynamicHandle(String lsh){
//        log.info("进入【0342-0344关联车牌号】");
//        Map<String,String> shztMap = new HashedMap();
//        //0342-0344 任意一张识别到车牌号就通过
//        VehZnshzlzpxx vehZnshzlzpxx_0342 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0342");
//        VehZnshzlzpxx vehZnshzlzpxx_0344 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh,"0344");
//        String dynamic = "[车牌号码-与实际值比对]";
//        String shzt_0342 = vehZnshzlzpxx_0342==null?"":vehZnshzlzpxx_0342.getShzt();
//        String shzt_0344 = vehZnshzlzpxx_0344==null?"":vehZnshzlzpxx_0344.getShzt();
//
//        if (vehZnshzlzpxx_0342!=null && vehZnshzlzpxx_0344!=null){//有这两种照片,并且都开启了车牌号识别配置，就需要关联车牌号
//            //null.contains会报空指针异常，需先转换
//            String shbtgyy_0342 = vehZnshzlzpxx_0342.getShbtgyy()==null?"":vehZnshzlzpxx_0342.getShbtgyy();
//            String shbtgyy_0344 = vehZnshzlzpxx_0344.getShbtgyy()==null?"":vehZnshzlzpxx_0344.getShbtgyy();
//
//            List<String> shbtgyy_0342_list = StringUtils.isNotBlank(shbtgyy_0342)?Arrays.asList(shbtgyy_0342.split(",")):new ArrayList<>();
//            List<String> shbtgyy_0344_list = StringUtils.isNotBlank(shbtgyy_0344)?Arrays.asList(shbtgyy_0344.split(",")):new ArrayList<>();
//
//            String jyx_0342 = vehZnshzlzpxx_0342.getJyx()==null?"":vehZnshzlzpxx_0342.getJyx();
//            String jyx_0344 = vehZnshzlzpxx_0344.getJyx()==null?"":vehZnshzlzpxx_0344.getJyx();
//
//            if (jyx_0342.contains("jy_084_001") && jyx_0344.contains("jy_083_001")){//是否都开启了大灯检验配置
//                if ((shbtgyy_0342.contains(dynamic) && !shbtgyy_0344.contains(dynamic))){
//                    shbtgyy_0342_list = shbtgyy_0342_list.stream().filter( v-> !dynamic.equals(v)).collect(Collectors.toList());
//                }
//                if (!shbtgyy_0342.contains(dynamic) && shbtgyy_0344.contains(dynamic)){
//                    shbtgyy_0344_list = shbtgyy_0344_list.stream().filter( v-> !dynamic.equals(v)).collect(Collectors.toList());
//                }
//                shzt_0342 = shbtgyy_0342_list.size()==0?"1":"5";
//                shzt_0344 = shbtgyy_0344_list.size()==0?"1":"5";
//
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0342,String.join(",",shbtgyy_0342_list),"0342");
//                vehZnshzlzpxxService.updateLinkedShzt(lsh,shzt_0344,String.join(",",shbtgyy_0344_list),"0344");
//            }
//        }
//        if (StringUtils.isNotBlank(shzt_0342))
//            shztMap.put("0342",shzt_0342);//加入已经处理过的0342判断结果
//        if (StringUtils.isNotBlank(shzt_0344))
//            shztMap.put("0344",shzt_0344);//加入已经处理过的0344判断结果
//        log.info("出来【0342-0344关联车牌号】");
//        return shztMap;
//    }
//
//    private Map<String, String> handleTripodLink(
//            String lsh,
//            String zpzl1,
//            String zpzl2,
//            String tripodKey,
//            String jyxKey1,
//            String jyxKey2
//    ) {
//        log.info("进入【{}-{} 关联{}处理】", zpzl1, zpzl2,tripodKey);
//        Map<String, String> shztMap = new HashMap<>();
//
//        VehZnshzlzpxx record1 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh, zpzl1);
//        VehZnshzlzpxx record2 = vehZnshzlzpxxService.GetVehZnshzlzpxx(lsh, zpzl2);
//
//        String shzt1 = record1 != null ? Optional.ofNullable(record1.getShzt()).orElse("") : "";
//        String shzt2 = record2 != null ? Optional.ofNullable(record2.getShzt()).orElse("") : "";
//        log.info("进入【{}-{} 关联处理{}--{}】", zpzl1, zpzl2,shzt1,shzt2);
//        if (record1 != null && record2 != null) {
//            String shbtgyy1 = Optional.ofNullable(record1.getShbtgyy()).orElse("");
//            String shbtgyy2 = Optional.ofNullable(record2.getShbtgyy()).orElse("");
//
//            List<String> list1 = StringUtils.isNotBlank(shbtgyy1) ? new ArrayList<>(Arrays.asList(shbtgyy1.split(","))) : new ArrayList<>();
//            List<String> list2 = StringUtils.isNotBlank(shbtgyy2) ? new ArrayList<>(Arrays.asList(shbtgyy2.split(","))) : new ArrayList<>();
//
//            String jyx1 = Optional.ofNullable(record1.getJyx()).orElse("");
//            String jyx2 = Optional.ofNullable(record2.getJyx()).orElse("");
//
//            if (jyx1.contains(jyxKey1) && jyx2.contains(jyxKey2)) {
//                log.info("进入【{}-{} 关联处理{}--{}】", zpzl1, zpzl2,jyx1,jyx2);
//                // 两者都开启了该检验项
//                if (list1.contains(tripodKey) && !list2.contains(tripodKey)) {
//                    list1 = list1.stream().filter(v -> !tripodKey.equals(v)).collect(Collectors.toList());
//                }
//                if (!list1.contains(tripodKey) && list2.contains(tripodKey)) {
//                    list2 = list2.stream().filter(v -> !tripodKey.equals(v)).collect(Collectors.toList());
//                }
//
//                shzt1 = list1.isEmpty() ? "1" : "5";
//                shzt2 = list2.isEmpty() ? "1" : "5";
//                vehZnshzlzpxxService.updateLinkedShzt(lsh, shzt1, String.join(",", list1), zpzl1);
//                vehZnshzlzpxxService.updateLinkedShzt(lsh, shzt2, String.join(",", list2), zpzl2);
//
//
//                xbjcMapper.updateShjg(lsh, shzt1.equals("5")?"2":"1",String.join(",", list1),zpzl1);
//                xbjcMapper.updateZpshbjByZpzl(lsh, shzt1.equals("5")?"2":"1",zpzl1);
//
//                xbjcMapper.updateShjg(lsh, shzt2.equals("5")?"2":"1",String.join(",", list2),zpzl2);
//                xbjcMapper.updateZpshbjByZpzl(lsh, shzt1.equals("5")?"2":"1",zpzl2);
//            }
//        }
//
//        if (StringUtils.isNotBlank(shzt1)) {
//            shztMap.put(zpzl1, shzt1);
//        }
//        if (StringUtils.isNotBlank(shzt2)) {
//            shztMap.put(zpzl2, shzt2);
//        }
//
//        log.info("出来【{}-{} 关联处理{}】", zpzl1, zpzl2,tripodKey);
//        return shztMap;
//    }
}
